package com.cuotibao.zhuoxiao.basics.utils.recyview;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * @author hdx on 2019/5/6.
 */
public class DividerSpaceItemDecoration extends RecyclerView.ItemDecoration {
    private int topOrBottomSpace;
    private int leftOrRightSpace;

    public DividerSpaceItemDecoration(int topOrBottomSpace) {
        this.topOrBottomSpace = topOrBottomSpace;
    }

    public DividerSpaceItemDecoration(int topOrBottomSpace, int leftOrRightSpace) {
        this(topOrBottomSpace);
        this.leftOrRightSpace = leftOrRightSpace;
    }


    @Override
    public void getItemOffsets(Rect outRect, View view,
                               RecyclerView parent, RecyclerView.State state) {
        outRect.left = leftOrRightSpace;
        outRect.right = leftOrRightSpace;
        outRect.bottom = topOrBottomSpace;
        if (parent.getChildPosition(view) == 0)
            outRect.top = topOrBottomSpace;
    }
}
